package com.candy.control;

import com.candy.bean.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/test")
    public void test(){
//        进行字符串的操作
//        ValueOperations<String,String> op1= stringRedisTemplate.opsForValue();
//        op1.set("userinfoname","tony");
//        String username=op1.get("userinfoname");
//        System.out.println(username);
//        进行对象的操作
        ValueOperations op2=  redisTemplate.opsForValue();
        UserInfo userinfo=new UserInfo();
        userinfo.setUsername("张三");
        userinfo.setUseraddress("山东青岛");
        userinfo.setUsertel("13132323232");
        op2.set("userinfonew",userinfo);
        UserInfo userinfo2= (UserInfo) op2.get("userinfonew");
        System.out.println(userinfo2);
    }




}
